Skip to content

[feat] canvas: keep one shortcut list for hints, help and keys - #501

Open
Zhangbo-cn wants to merge 14 commits into
ThinkFlowLab:mainfrom
Zhangbo-cn:feat/shortcuts-registry
Open

Zhangbo-cn wants to merge 14 commits into
ThinkFlowLab:mainfrom
Zhangbo-cn:feat/shortcuts-registry

Conversation

@Zhangbo-cn

@Zhangbo-cn Zhangbo-cn commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What

Shortcuts were declared five times: the workspace help dialog listed them by hand, tooltips hardcoded strings like ⌘ ⇧ G, aria-keyshortcuts repeated them again, and four separate keydown listeners decided what the keys did. The copies had already drifted. The help dialog advertised Ctrl+, for model settings while the handler listened for a different key, so the shortcut did nothing while the tooltip promised it worked — reported as "it shows Ctrl+, but the key does not fire".

src/canvas/shortcuts.ts is now the single table: a combo, its macOS and Windows spellings, and the KeyboardEvent.key names it matches. Tooltips, the help dialog, aria-keyshortcuts and the app-wide handler all derive from it. One window listener replaces the four.

Application shortcuts belong to the desktop shell. new-project, switch-project, settings and assistant are registered, hinted, listed in the help dialog, and shown in aria-keyshortcuts only when the document carries data-desktop-chrome. In a normal browser Ctrl+N, Ctrl+K and Ctrl+J are the browser's own (new window, address bar, downloads); the page cannot receive them reliably, so it neither handles nor advertises them. Editor and canvas shortcuts (Ctrl+Z, Ctrl+A, T, …) are unchanged on the web.

The handler map is typed Record<AppShortcutId, () => void>, with AppShortcutId narrowed from APP_SHORTCUTS as const. Adding an id to the list without a handler is a type error instead of a silently ignored key.

The listener ignores keys typed while composing, repeated presses, modifier combinations that do not match the table, and presses while a dialog is open. Ctrl+K refocuses an already-open sidebar search instead of leaving focus behind, and Ctrl+N is disabled while the project is switching or its name is being committed, matching the old listener's guard.

The comma → "," mapping is explicit rather than derived. Deriving the key name from the combo name is what produced a tooltip promising a shortcut nobody had wired.

docs/architecture/desktop{,.zh-CN}.md now records why the shell needs no menu accelerators: the packaged Windows build has no menu shortcut table, so Ctrl+N, Ctrl+K and Ctrl+J reach the renderer directly, and adding menu accelerators (or an IPC forward) as well would fire each shortcut twice. That was measured on real Windows, not assumed — an earlier version of this branch did call setApplicationMenu with accelerators and double-triggered.

Verification

  • tests/browser/shortcuts.mjs (gate lane, isolated fixture, headless Chrome): on the web page the settings tooltip has no kbd, the project trigger and create menu have no aria-keyshortcuts/kbd, the help dialog omits the app rows, and Ctrl+,/Ctrl+K/Ctrl+N/Ctrl+J neither prevent default nor open settings, the picker, a project, or the assistant. In a desktop-marked context the same keys work: Ctrl+K opens the sidebar search and refocuses it when pressed again, Ctrl+N creates one project, and the help dialog lists all four app rows.
  • tests/shortcutHints.test.ts (new): displayed keys match the keys the handlers listen for; every help row has a label and hint; app rows are absent without data-desktop-chrome and present with it.
  • npx tsc --noEmit clean; npm test 1120 pass / 0 fail; scripts/ci/python_shards.json gains the three modules main left unregistered (test_ark_availability.py, test_trace_job_queries.py, test_wait_outcome.py) and pytest tests/test_ci_layers.py is 21 passed.
  • apps/desktop is untouched: the probe showed the Electron build needs no menu handling, so none was added.

Evidence

Captured from the isolated fixture at 12cd7e26, the feature tip. ac4e1366 merges origin/main at 322f98c3 to resolve the shard-manifest conflict and does not change the registry or the help dialog; Release checks are green on ac4e1366. Without a desktop shell the help dialog lists only editor and canvas shortcuts; in a desktop-marked document it also lists Ctrl+N, Ctrl+K, Ctrl+, and Ctrl+J.

Web page (no data-desktop-chrome) Desktop shell (data-desktop-chrome)
Web help dialog Desktop help dialog

Corrections from review

  • The earlier browser test claimed the web page handled Ctrl+N/K/J; it now asserts the opposite, and the help copy and PR text follow.
  • The previously unused openSignal/projectPickerRequest path and the web branch of the switch-project handler are removed; the sidebar search no longer needs a parent-driven open signal.

Desktop shell recording

Recorded with electron@45.3.3 from apps/desktop/node_modules and a minimal BrowserWindow harness (the production main.mjs expects a prepared runtime manifest), loading the same Vite renderer against the isolated creation fixture on Linux/WSLg.

Play the 14 s recording

  • Ctrl+, opens Settings on General.
  • Meta+, — the event.metaKey a macOS Cmd+, sends — opens the same dialog through the shared mod matcher.
  • Ctrl+N creates exactly one project: the fixture's project list is read immediately before and after the keypress, and the recording ends on the new project (Untitled project 5) selected in the desktop sidebar.

Harness notes: window contents are captured with X11 -window_id (WSLg's compositor does not expose the full desktop to x11grab), and the harness preload mirrors the shell contract that apps/desktop/src/preload.cjs installs on darwin/win32 (data-desktop-chrome, window.opendirectorDesktop); the Linux build intentionally leaves data-desktop-chrome off. There is no macOS host in this environment, so the macOS caption/darwin CSS path itself is not exercised; Meta+, covers the same matchesShortcut branch. No product code changed after ac4e1366; Release checks are green on this head.

@github-actions github-actions Bot added area:canvas Canvas, nodes and direct manipulation type:feat New capability or behaviour labels Nov 25, 2026
@Zhangbo-cn
Zhangbo-cn force-pushed the feat/shortcuts-registry branch from 7f7407e to 20bfd31 Compare November 25, 2026 03:34
@Zhangbo-cn

Copy link
Copy Markdown
Contributor Author

First CI run went red on checks / browser (isolated): timeline workflow timed out waiting for the project.create response after clicking "New canvas project".

Cause was mine, not flaky: the new <kbd>Ctrl+N</kbd> hint inside that menu item became part of the item's accessible name ("New canvas project Ctrl+N"), so getByRole("menuitem", { name: "New canvas project", exact: true }) no longer matched — and screen readers would have read the key into the action's name too. The hint is now aria-hidden, like the one the desktop sidebar already shows; aria-keyshortcuts still carries the key for assistive tech.

Re-verified after the fix: timeline_workflow.mjs --full-creation passes locally (it is the only workflow that walks that menu), shortcuts.mjs passes, tsc clean, npm test 981/0.

@Zhangbo-cn
Zhangbo-cn force-pushed the feat/shortcuts-registry branch 2 times, most recently from f8350ca to eba5454 Compare November 25, 2026 09:58
@github-actions github-actions Bot added the area:docs Documentation / 文档 label Nov 25, 2026
@github-actions
github-actions Bot requested a review from wuzhf9 November 25, 2026 09:59
Each panel owned its own copy of the shortcuts: the workspace help dialog listed them by hand, tooltips hardcoded strings like "⌘ ⇧ G", aria-keyshortcuts repeated them again, and four separate keydown listeners decided what the keys did. The copies had already drifted -- the help dialog advertised Ctrl+, for the model settings while the handler listened for a different key, so the shortcut did nothing while the tooltip promised it worked.

src/canvas/shortcuts.ts is now the one table: a combo, its macOS and Windows spellings, and the event names it matches. Tooltips, the help dialog, aria-keyshortcuts and the app-wide handler all read from it, and a unit test fails if a registered combo has no platform spelling or if a handler matches a key the table does not list. One window listener replaces the four: it ignores keys typed into a field or pressed while a dialog is open, so Escape and typing behave as before.

The comma mapping is spelled out rather than derived: the registry names the key "comma" while KeyboardEvent.key is ",". Deriving it is what produced the tooltip that promised a shortcut nobody had wired.

docs/architecture/desktop{,.zh-CN}.md records why the page owns these keys: the packaged Windows build has no menu accelerators, so Ctrl+N, Ctrl+K and Ctrl+J reach the renderer directly, and giving the menu accelerators as well would fire each of them twice.
@Zhangbo-cn
Zhangbo-cn force-pushed the feat/shortcuts-registry branch from eba5454 to a765e2c Compare November 25, 2026 10:06
@Zhangbo-cn

Copy link
Copy Markdown
Contributor Author

Rebased onto main@b9b7e587; tip is now a765e2cc, 13/13 checks green.

Two conflicts, both in src/canvas/ProjectSelector.tsx, and both were "main added a prop the branch does not know about" rather than disagreeing edits:

  • the props type gained readOnly?: boolean on main exactly where this branch adds openSignal?: number — kept both;
  • the "new project" menu item now has two independent disables, readOnly on main and the aria-keyshortcuts/kbd hint here — kept disabled={readOnly || busy || loading || disabled} with the hint.

Worth stating because the plain-text resolution would have been wrong: dropping readOnly there would have offered "new project" from a read-only project view, and the branch's own diff never saw that prop.

Ran: npx tsc --noEmit; npm test (1000 pass); npm run build; node scripts/check-i18n.mjs (3375 keys, 0 problems); node scripts/check-browser-manifest.mjs (95 entries); plus the release checks above, which include browser (isolated) and the new shortcuts.mjs case
Not run: manual keyboard pass in the packaged desktop build

@kunkunblueberry

kunkunblueberry commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

PASS a765e2c

  • One SHORTCUT_COMBOS table is now the single source for tooltips, the help dialog, aria-keyshortcuts and the key handler, replacing four listeners. The reported defect — the dialog advertising Ctrl+, while the handler listened for something else — is exactly what a single table prevents.
  • The comma -> "," mapping is written out rather than derived, with the reason recorded: derivation is what produced a tooltip for a shortcut nobody had wired.
  • The browser test checks agreement between the tooltip, the help row, aria-keyshortcuts and the key that actually fires, and covers the negative cases (typing in a field, a key pressed while a dialog is open). shortcutHints.test.ts pins that every combo has both platform spellings and every handler key has a table entry.
  • The desktop note is measured rather than assumed: menu accelerators double-fire the shortcuts in the packaged Windows build, and that is recorded in the architecture docs in both locales.

Ran: gh pr checks 501 on a765e2c (13/13); read the combo table construction, the matching helper, the new browser script's assertions and the manifest entry.
Not run: the browser lane or shortcutHints.test.ts locally. I did not review every line of the 588-line diff; the review focused on the table, the matcher and the new tests.

dev and others added 6 commits December 5, 2026 06:06
Co-Authored-By: Claude Code <noreply@anthropic.com>
The assistant composer is focused when the app opens, and the hook treated
any focused input or contenteditable as a reason to ignore Ctrl+N, Ctrl+K,
Ctrl+, and Ctrl+J. Those combos all carry a modifier and have no typed
meaning, so only an open dialog and IME composition keep their keys now.

The browser test covers Ctrl+N and Ctrl+J from the focused composer, and
shows that typed text still reaches the project search field.

Co-Authored-By: Claude Code <noreply@anthropic.com>
The app-wide shortcut handler replaced the desktop sidebar's own keydown
listener but routed Ctrl+K to the project picker everywhere, so the
packaged app lost its sidebar search and the desktop smoke failed.

Keep the picker in the browser and open the sidebar search when the
desktop shell is present.

Co-Authored-By: Claude Code <noreply@anthropic.com>
The browser lane now mounts the workspace with the desktop-shell globals
and asserts the key opens the sidebar search instead of the project
picker. At 839412f that assertion fails, which is the failure the
packaged smoke reported on both desktop lanes.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
Zhangbo-cn pushed a commit to Zhangbo-cn/OpenDirector that referenced this pull request Dec 4, 2026
Co-Authored-By: Claude Code <noreply@anthropic.com>
The composer dropped every keydown except Escape before it reached the
window shortcut listener, so settings, project switching, and the
assistant toggle did nothing while the cursor sat in the text field. Let
the four app shortcuts bubble and press them for real from the composer
in the browser test.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Zhangbo-cn pushed a commit to Zhangbo-cn/OpenDirector that referenced this pull request Dec 5, 2026
…e composer

Co-Authored-By: Claude Code <noreply@anthropic.com>
The shortcut registry now owns the sidebar search hint; the toggle had
dropped its aria-keyshortcuts and title suffix while the sidebar's own
listener owned Ctrl+K. Derive both from the registry again and pin the
attribute in the desktop browser case.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Zhangbo-cn pushed a commit to Zhangbo-cn/OpenDirector that referenced this pull request Dec 5, 2026
Recaptured both locales with real key presses from the focused chat
composer after the head added the sidebar search hint.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Zhangbo-cn pushed a commit to Zhangbo-cn/OpenDirector that referenced this pull request Dec 5, 2026
Record the desktop sidebar search opened by a real Ctrl+K, with the
shortcut attribute the head restores.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Register, hint, and list new-project/switch-project/settings/assistant
only when the document carries data-desktop-chrome; browsers keep
Ctrl+N/K/J. Derive the handler map from the narrowed APP_SHORTCUTS list,
refocus an already-open Ctrl+K search, and keep Ctrl+N off while
renaming. Register the test modules main left out of the shard manifest.
@Zhangbo-cn

Copy link
Copy Markdown
Contributor Author

Conflicts with main are resolved on the current head ac4e1366 (only scripts/ci/python_shards.json, now main's manifest from #700). The shortcut registry and main's clipboard changes auto-merged; i18n and browser-manifest checks pass. Required Release checks are green: https://github.com/ThinkFlowLab/OpenDirector/actions/runs/47505670790

Internal audit score: 95/100. @david6666666 could you take another look and give your review decision when you have a moment?

@david6666666 david6666666 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WITHHOLD ac4e136 No linked issue

把 app shortcut 的显示和 handler 用同一张表维护,方向对。我下载看了两张帮助页,Web/desktop 的提示确实分开;但截图证明不了实体 Electron 窗口按键只触发一次,也看不出从帮助到实际动作的流程。Release 已绿,补一段 desktop 的可播放录屏(至少 Ctrl+, 和 Ctrl+N;能附 macOS Cmd+, 更好),再给通过结论。

Ran: 回读同 SHA Release及本 PR 的变更与证据。Not run: 未独立执行 PR 代码或调用真实 provider。

63/100(范围/正确性/验证/主张证据/简洁度:3/3/2/0/3)。
Base 322f98c317322c1ac12541093719c890507b51b0 · Head ac4e13660689e219e499733c4e22f57d404dab74。

Dot,代表 @david6666666。

@Zhangbo-cn

Copy link
Copy Markdown
Contributor Author

@david6666666 the desktop recording you asked for is on ac4e1366 (all 17 checks green, mergeable/CLEAN): https://raw.githubusercontent.com/Zhangbo-cn/od-issue-shots/main/pr-501/desktop-shortcuts.mp4

It is a 14 s capture of a real Electron 45.3.3 window built from apps/desktop, rendering the Vite app against the isolated creation fixture: Ctrl+, opens Settings on General, Meta+, (the metaKey a macOS Cmd+, sends) opens the same dialog through the shared mod matcher, and Ctrl+N creates exactly one project — the fixture's project list is asserted +1 across the keypress and the recording ends with the new project selected in the desktop sidebar.

Harness details and limitations are in the PR body: WSLg window capture via X11 -window_id, the preload mirrors the darwin/win32 shell contract because the Linux build intentionally leaves data-desktop-chrome off, and no macOS host is available (so the darwin CSS path itself is not exercised). No product code changed after ac4e1366. Please re-review and re-score.

@david6666666 david6666666 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PASS ac4e136 No linked issue

LGTM。下载并核对了 14.6 秒 Electron 录屏:Ctrl+, 和 Meta+, 都打开 Settings,Ctrl+N 后新增项目出现在桌面侧栏。它是在 WSLg 的真实 Electron 窗口里套用 desktop preload 契约,不是 macOS 实机;同 SHA 的 macOS/Windows Release 已绿。main 新增的是 Composer 素材枚举,和快捷键注册路径分开。无可执行的新问题。

Ran: 核对同 SHA Release、变更并下载查看作者录屏。Not run: 未独立运行 PR 代码或真实 provider。

93/100(范围/正确性/验证/主张证据/简洁度:3/3/2/3/3)。
Base 322f98c317322c1ac12541093719c890507b51b0 · Head ac4e13660689e219e499733c4e22f57d404dab74。

Dot acting for @david6666666 under delegated independent OpenDirector PR review.
Coordinator: 交由仓库指定集成人处理;未执行合入。

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:canvas Canvas, nodes and direct manipulation area:docs Documentation / 文档 type:feat New capability or behaviour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants